﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Clients.aspx.cs" Inherits="GPSTrackingWebsiteManager.Manager.Pages.Clients" %>

<!DOCTYPE html>

<link href="../../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<link href="../../Css/messi.css" rel="stylesheet" />
<script src="../../Javascript/jquery-1.11.1.min.js"></script>
<script src="../../Javascript/messi.js"></script>
<script src="../../Javascript/Custom.js"></script>
<script src="../../Javascript/WindowMessageManager.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">

<telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
    <script type="text/javascript">
        function resizeGrid() {
            var height = (window.innerHeight) - 25;
            var tableView = $find("<%=ClientsGroupGrid.ClientID %>");
            tableView.get_element().style.height = (height) / 2 + "px";

            var tableView2 = $find("<%=ClientsGrid.ClientID %>");
            tableView2.get_element().style.height = (height - (height) / 2) + "px";
            
            document.getElementById('HiddenFieldHeight').value = (height);
        }

        function OpenEmails() {
            var wnd = $find('<%=rwEmails.ClientID %>');
            wnd.show();
            resizeGrid();
        }

        //Windows Message Manager 
        var objWindowsMessageManager = new WindowsMessageManager();


    </script>
</telerik:RadScriptBlock>

<head runat="server">
    <title>Administración de Clientes</title>
</head>
<body onresize="resizeGrid()" style="overflow: hidden">
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>      
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="ClientsGroupGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rmpClients" LoadingPanelID="RadAjaxLoadingPanel1" UpdatePanelCssClass="" />
                    <telerik:AjaxUpdatedControl ControlID="HiddenFieldError" /> 
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="ClientsGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="ClientsGrid" LoadingPanelID="RadAjaxLoadingPanel1" UpdatePanelCssClass="" />
                    <telerik:AjaxUpdatedControl ControlID="HiddenFieldError" /> 
                    <telerik:AjaxUpdatedControl ControlID="EmailsGrid" LoadingPanelID="RadAjaxLoadingPanel1" UpdatePanelCssClass="" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="EmailsGrid">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="HiddenFieldHeight" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="HiddenFieldError" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="EmailsGrid" LoadingPanelID="RadAjaxLoadingPanel1" UpdatePanelCssClass="" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
    <asp:HiddenField ID="HiddenFieldHeight" runat="server" Value="323" />
    <asp:HiddenField ID="HiddenFieldError" runat="server" Value="" />

        <telerik:RadTabStrip ID="rtsClients" runat="server" SelectedIndex="0" MultiPageID="rmpClients" ></telerik:RadTabStrip>
        <telerik:RadMultiPage ID="rmpClients" runat="server" SelectedIndex="0">
        <telerik:RadPageView ID="rpvClients" runat="server">

        <div>
                <telerik:RadGrid ID="ClientsGroupGrid" ShowStatusBar="true" runat="server" AllowMultiRowSelection="false" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100%" Width="100%" OnNeedDataSource="ClientsGroupGrid_NeedDataSource" OnSelectedIndexChanged="ClientsGroupGrid_SelectedIndexChanged" AllowSorting="true" GroupingSettings-CaseSensitive="false" OnItemCommand="ClientsGroupGrid_ItemCommand">
                    <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                        </Scrolling>  <Selecting AllowRowSelect="True"></Selecting><ClientEvents OnPopUpShowing="PopUpShowing" />
                    </ClientSettings>
                        <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" CommandItemDisplay="TopAndBottom" NoMasterRecordsText="No hay registros" AllowFilteringByColumn="true" TableLayout="Auto">
                        <CommandItemTemplate>
                            <div style="padding: 5px 5px;"> Grupo Clientes: 
                                    <asp:LinkButton ID="lbClearClientsGroupsFilters" runat="server" OnClick="lbClearClientsGroupsFilters_Click"  Visible='<%# !ClientsGroupGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/mixx-icon.png"/>Limpiar Filtros</asp:LinkButton>                                                                               
				                    <asp:LinkButton ID="lbShowError" runat="server" OnClick="lbShowError_Click" Visible='<%# HiddenFieldError.Value == string.Empty ? false : true %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/bug-icon.png"/>Error Técnico</asp:LinkButton>                                                                                                               
                            </div>                        
                        </CommandItemTemplate>

                        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>

                        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>

                        <Columns>
                            <telerik:GridButtonColumn UniqueName="SelectColumn" CommandName="Select" Text="Seleccionar" HeaderStyle-Width="20px" ButtonType="ImageButton" ImageUrl="../../Template/Icons/16px/User-Group-Blue-icon.png" />
                            
                            <telerik:GridBoundColumn DataField="ClientGroupId" FilterControlAltText="Filter Name column" HeaderText="Grupo ID" UniqueName="ClientGroupId" ReadOnly="true" ForceExtractValue="Always" Display="true" HeaderStyle-Width="100px" MaxLength="50" FilterControlWidth="80px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" AllowFiltering="true" >
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ClientGroupIdSource.Name" FilterControlAltText="Filter Name column" HeaderText="Nombre" MaxLength="50" UniqueName="Name" HeaderStyle-Width="200px" FilterControlWidth="180px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
                            </telerik:GridBoundColumn>
                        </Columns>

                        <EditFormSettings>
                        <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
                        </EditFormSettings>

                        <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
                    </MasterTableView>

<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>

                    <FilterMenu EnableImageSprites="False"></FilterMenu>
                </telerik:RadGrid>
        </div>
            <br/>
        <div>
                <telerik:RadGrid ID="ClientsGrid" runat="server" AllowFilteringByColumn="true" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100%" Width="100%" OnDeleteCommand="ClientsGrid_DeleteCommand" OnInsertCommand="ClientsGrid_InsertCommand" OnNeedDataSource="ClientsGrid_NeedDataSource" OnUpdateCommand="ClientsGrid_UpdateCommand" AllowSorting="true" GroupingSettings-CaseSensitive="false" OnSelectedIndexChanged="ClientsGrid_SelectedIndexChanged" OnItemCommand="ClientsGrid_ItemCommand">
		            <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" CommandItemDisplay="TopAndBottom" NoMasterRecordsText="No hay registros" TableLayout="Auto">
                    <CommandItemTemplate>
                        <div style="padding: 5px 5px;"> Clientes: 
                                <asp:LinkButton ID="lbAdd" runat="server" CommandName="InitInsert" Visible='<%# !ClientsGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/text-plus-icon.png"/>Nuevo Cliente</asp:LinkButton>
                                <asp:LinkButton ID="lbAddEmails" CommandName="AddEmails" runat="server" OnClientClick="OpenEmails()"><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/text-plus-icon.png"/>Asociar Correos</asp:LinkButton>
                                <asp:LinkButton ID="lbClearClientsFilters" runat="server" OnClick="lbClearClientsFilters_Click"  Visible='<%# !ClientsGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/mixx-icon.png"/>Limpiar Filtros</asp:LinkButton>                                                                               
				                <asp:LinkButton ID="lbShowError" runat="server" OnClick="lbShowError_Click" Visible='<%# HiddenFieldError.Value == string.Empty ? false : true %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/bug-icon.png"/>Error Técnico</asp:LinkButton>                                                                                                               
                        </div>                        
                    </CommandItemTemplate>

                        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>

                        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>

                        <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="25px" EditText="Editar" ItemStyle-Width="20px"/>
                        <telerik:GridButtonColumn HeaderStyle-Width="25px" ConfirmText="¿Desea eliminar el registro?" ConfirmDialogType="RadWindow" ConfirmDialogHeight="120" ConfirmDialogWidth="270" ConfirmTitle="Eliminar" ButtonType="ImageButton" CommandName="Delete" Text="Eliminar" ItemStyle-Width="20px" />
                            <telerik:GridBoundColumn DataField="ClientId" FilterControlAltText="Filter ClienteId column" ForceExtractValue="Always" HeaderText="Cliente ID" ReadOnly="True" UniqueName="ClientId" Display="true" HeaderStyle-Width="100px" MaxLength="50" FilterControlWidth="80px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" HeaderText="Nombre" UniqueName="Name" HeaderStyle-Width="200px" MaxLength="50" FilterControlWidth="180px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
                                 <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                    <RequiredFieldValidator ForeColor="Red" ErrorMessage="* Requerido" SetFocusOnError="true"></RequiredFieldValidator>
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridNumericColumn DataField="Latitude" DataType="System.Decimal" DecimalDigits="10" FilterControlAltText="Filter Latitude column" HeaderText="Latitud" MaxLength="12" UniqueName="Latitude" HeaderStyle-Width="200px" FilterControlWidth="180px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" ReadOnly="true" ForceExtractValue="Always" >
                            </telerik:GridNumericColumn>
                            <telerik:GridNumericColumn DataField="Longitude" DataType="System.Decimal" DecimalDigits="10" FilterControlAltText="Filter Longitude column" HeaderText="Longitud" MaxLength="12" UniqueName="Longitude" HeaderStyle-Width="200px" FilterControlWidth="180px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" ReadOnly="true" ForceExtractValue="Always">
                            </telerik:GridNumericColumn>
                            <telerik:GridMaskedColumn DataField="Phone1" DataFormatString="{0:########}" DisplayMask="" FilterControlAltText="Filter Phone column" HeaderText="Teléfono 1" Mask="########" UniqueName="Phone1" HeaderStyle-Width="100px" FilterControlWidth="80px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
                            </telerik:GridMaskedColumn>
                            <telerik:GridMaskedColumn DataField="Phone2" DataFormatString="{0:########}" DisplayMask="" FilterControlAltText="Filter Phone column" HeaderText="Teléfono 2" Mask="########" UniqueName="Phone2" HeaderStyle-Width="100px" FilterControlWidth="80px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
                            </telerik:GridMaskedColumn>
                                                    
                        </Columns>

                        <EditFormSettings>
                            <EditColumn InsertText="Agregar" UpdateText="Actualizar" CancelText="Cancelar" ButtonType="ImageButton"></EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                        </Scrolling>  <Selecting AllowRowSelect="True"></Selecting><ClientEvents OnPopUpShowing="PopUpShowing" />
                    </ClientSettings>
                    <FilterMenu EnableImageSprites="False"></FilterMenu>
                </telerik:RadGrid>
        </div>
            <div>
                    <telerik:RadWindow ID="rwEmails" runat="server" Width="605px" Height="505px" EnableShadow="true" Behaviors="Close" ShowContentDuringLoad="false" VisibleStatusbar="false" Modal="true">
                <ContentTemplate>
                    <telerik:RadGrid ID="EmailsGrid" runat="server"  AllowSorting="true" AllowFilteringByColumn="false" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Width="572px" Height="452px" GroupingSettings-CaseSensitive="false" OnNeedDataSource="EmailsGrid_NeedDataSource" OnInsertCommand="EmailsGrid_InsertCommand" OnUpdateCommand="EmailsGrid_UpdateCommand" OnDeleteCommand="EmailsGrid_DeleteCommand">
                        <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" CommandItemDisplay="TopAndBottom" NoMasterRecordsText="No hay registros">
                            <CommandItemTemplate>
                                <div style="padding: 5px 5px;">
                                    Menu: 
                             <asp:LinkButton ID="lbAdd" runat="server" CommandName="InitInsert" Visible='<%# !EmailsGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/text-plus-icon.png"/>Nuevo Correo</asp:LinkButton>
                                    <asp:LinkButton ID="lbClearEmailFilters" runat="server" OnClick="lbClearEmailFilters_Click"  Visible='<%# !EmailsGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/mixx-icon.png"/>Limpiar Filtros</asp:LinkButton>                                                                               
				                <asp:LinkButton ID="lbShowError" runat="server" OnClick="lbShowError_Click" Visible='<%# HiddenFieldError.Value == string.Empty ? false : true %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/bug-icon.png"/>Error Técnico</asp:LinkButton>                                                                                                               
                                </div>
                            </CommandItemTemplate>
                            <CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="Nuevo Master" RefreshText="Actualizar"></CommandItemSettings>

                            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>

                            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>

                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="25px" EditText="Editar" ItemStyle-Width="20px"/>
                                <telerik:GridButtonColumn ConfirmText="¿Desea eliminar el registro?" Text="Eliminar" ConfirmDialogType="RadWindow" ConfirmDialogHeight="120" ConfirmDialogWidth="270" ConfirmTitle="Eliminar" ButtonType="ImageButton" CommandName="Delete" HeaderStyle-Width="25px" />
                                <telerik:GridBoundColumn DataField="ClientId" HeaderText="Código Cliente" UniqueName="ClientId" ForceExtractValue="Always" Display="false" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EmailId" HeaderText="ID Email" UniqueName="EmailId" ForceExtractValue="Always" ReadOnly="true" Display="false" FilterControlWidth="80px" CurrentFilterFunction="Contains" ShowFilterIcon="false" HeaderStyle-Width="100px" AutoPostBackOnFilter="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Name" HeaderText="Nombre Correo" UniqueName="Name" ForceExtractValue="Always" FilterControlWidth="30px" CurrentFilterFunction="Contains" ShowFilterIcon="false" HeaderStyle-Width="50px" AutoPostBackOnFilter="true" Display="true" ItemStyle-HorizontalAlign="Center">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Email" HeaderText="Correo" UniqueName="Email" ForceExtractValue="Always" FilterControlWidth="30px" CurrentFilterFunction="Contains" ShowFilterIcon="false" HeaderStyle-Width="50px" AutoPostBackOnFilter="true" Display="true" ItemStyle-HorizontalAlign="Center">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="LastTick" HeaderText="LastTick" UniqueName="LastTick" Display="false" ReadOnly="true" ForceExtractValue="Always"
                                    FilterControlWidth="100px" CurrentFilterFunction="Contains" ShowFilterIcon="false" HeaderStyle-Width="130px" AutoPostBackOnFilter="true">
                                </telerik:GridBoundColumn>
                            </Columns>

                            <EditFormSettings>
                                <EditColumn InsertText="Agregar" UpdateText="Actualizar" CancelText="Cancelar" ButtonType="ImageButton"></EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                        <ClientSettings EnableRowHoverStyle="true">
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True"></Scrolling>
                            <Selecting AllowRowSelect="True"></Selecting>
                        </ClientSettings>
                        <FilterMenu EnableImageSprites="False"></FilterMenu>
                    </telerik:RadGrid>

                </ContentTemplate>
            </telerik:RadWindow>
                </div>
        </telerik:RadPageView>
        </telerik:RadMultiPage>

    </form>
</body>
</html>
